package com.socket3;

import java.util.ArrayList;

import com.socket.entity.BmsEntity;
import com.socket.entity.MapEntity;
import com.socket.entity.PositionOffset;
import com.socket.entity.SpatEntity;
import com.socket.entity.TimEntity;

public class DataParse {
	public static void main(String[] args) {

		// 1
		// System.out.println(getBms("").toString());

		// 2
		ArrayList<SpatEntity> listSpatEntities = getSpat("");
		for (SpatEntity spatEntity : listSpatEntities) {
			System.out.println(spatEntity.toString());

		}

		// 3
		// System.out.println(getTim("").toString());
		// 4
		// ArrayList<MapEntity> mapList=getMap("");
		// for (MapEntity mapEntity : mapList) {
		// System.out.println(mapEntity.toString());
		//
		// }
	}

	public static BmsEntity getBsm(String data) {
		data = "" + "304f8001"
				+ "02812661"
				+ "74e41fab"
				+ "c418"
				+ "1280769c"// 28
				+ "48448ca2"// 36
				+ "00c8"// 44
				+ "78184000"
				+ "e001"// 56
				+ "7080"
				+ "7ffff907"
				+ "d1817fff"
				+ "0000"
				+ "2d0"// 84-87
				+ "14a"// 87-90
				+ "a20aa20880027fff810200c8a316b114800100a106800100810100820100830100840100";
		String lat = data.substring(28, 28 + 8);
		String lon = data.substring(36, 36 + 8);
		String altitude = data.substring(44, 44 + 4);
		String speed = data.substring(56, 56 + 4);
		String carWidth = data.substring(84, 84 + 3);
		String carLong = data.substring(87, 87 + 3);

		BmsEntity entity = new BmsEntity(Long.parseLong(lat, 16),
				Long.parseLong(lon, 16), Integer.parseInt(altitude, 16),
				Integer.parseInt(speed, 16), Integer.parseInt(carWidth, 16),
				Integer.parseInt(carLong, 16));
		return entity;

	}

	public static ArrayList<SpatEntity> getSpat(String data) {
		data = "" + "306180010da25c305a810400000000820100a54f30108202" + "0102"// 48
																				// 52
				+ "8301" + "02"// 56 58
				+ "8601" + "1d"// 62 64
				+ "8701" + "03"// 68 70
				+ "8b01" + "03"// 74 76
				+ "30128204" + "03040506"// ////84 92
				+ "8301" + "04"// 96 98
				+ "8601" + "6c"// 102 104
				+ "8701" + "03"// 108 110
				+ "8b01" + "03"// 114 116
				+ "30118203" + "070809"// 124 130
				+ "8301" + "02"// 134 136
				+ "8601" + "1d"// 140 142
				+ "8701" + "03"// 146 148
				+ "8b01" + "03"// 152 154
				+ "30148205" + "0a0b0c0d0e"// 162 172
				+ "8301" + "02"// 176 178
				+ "8602" + "0198"// 182 186
				+ "8701" + "03"// 190 192
				+ "8b01" + "03";// 194 196

		String laneSet = data.substring(48, 52);
		String currState = data.substring(56, 58);
		String timeToChange = data.substring(62, 64);
		String timeLikeklyToChange = data.substring(68, 70);

		String laneSet1 = data.substring(84, 92);
		String currState1 = data.substring(96, 98);
		String timeToChange1 = data.substring(102, 104);
		String timeLikeklyToChange1 = data.substring(108, 110);

		String laneSet2 = data.substring(124, 130);
		String currState2 = data.substring(134, 136);
		String timeToChange2 = data.substring(140, 142);
		String timeLikeklyToChange2 = data.substring(146, 148);

		String laneSet3 = data.substring(162, 172);
		String currState3 = data.substring(176, 178);
		String timeToChange3 = data.substring(182, 186);
		String timeLikeklyToChange3 = data.substring(190, 192);

		ArrayList<SpatEntity> list = new ArrayList<SpatEntity>();
		SpatEntity entity = new SpatEntity(0, laneSet, Integer.parseInt(
				currState, 16), Integer.parseInt(timeToChange, 16));

		SpatEntity entity1 = new SpatEntity(0, laneSet1, Integer.parseInt(
				currState1, 16), Integer.parseInt(timeToChange1, 16));

		SpatEntity entity2 = new SpatEntity(0, laneSet2, Integer.parseInt(
				currState2, 16), Integer.parseInt(timeToChange2, 16));

		SpatEntity entity3 = new SpatEntity(0, laneSet3, Integer.parseInt(
				currState3, 16), Integer.parseInt(timeToChange3, 16));
		list.add(entity);
		list.add(entity1);
		list.add(entity2);
		list.add(entity3);
		return list;

	}

	public static TimEntity getTim(String data) {
		data = "" + "30818e80" + "01108109" + "00000000" + "005f4943"
				+ "45830101" + "a4773075" + "800102a1" + "1ba119a0" + "108004"
				+ "1298b13a"// 70 78
				+ "8104" + "4863674c"// 82 90
				+ "8202" + "00a5"// 94 98
				+ "8102" + "000f"// 102 106
				+ "8201" + "02"// 110 112
				+ "8202" + "07e0"// 116 120
				+ "8303" + "05aeb0"// 124 130
				+ "8402" + "7d00"// 134 138
				+ "8501" + "02"// 142 144
				+ "a6108004" + "1298b13a"// 152 160
				+ "8104" + "4863674c"// 164 172
				+ "8202" + "00a5"// 176 180
				+ "8702" + "0258"// 184 188
				+ "8801" + "00"// 192 194
				+ "a91e301c8002" + "000f"// 206 210
				+ "a216a014a3120404" + "14090d8e"// 226 234
				+ "0404" + "17260fa1"// 238 246
				+ "0404" + "12b30c89"// 250 258
				+ "aa0aa0083006a0048002171885020000";

		String lat = data.substring(70, 78);
		String lon = data.substring(82, 90);
		String altitude = data.substring(94, 98);
		String viewAngle = data.substring(102, 106);
		String mutcdCode = data.substring(110, 112);

		String startYear = data.substring(116, 120);
		String startTime = data.substring(124, 130);
		String durationTime = data.substring(134, 138);

		String priority = data.substring(142, 144);// 优先级

		String commonAnchor_lat = data.substring(152, 160);// 起点
		String commonAnchor_lon = data.substring(164, 172);
		String commonAnchor_elevation = data.substring(176, 180);
		String commonLaneWidth = data.substring(184, 188);// 车道宽度
		String commonDirectionality = data.substring(192, 194);
		ArrayList<PositionOffset> nodeList = new ArrayList<PositionOffset>();//
		String x = data.substring(226, 230);
		String y = data.substring(230, 234);

		String x1 = data.substring(238, 242);
		String y1 = data.substring(242, 246);

		String x2 = data.substring(250, 254);
		String y2 = data.substring(254, 258);

		PositionOffset offset = new PositionOffset(Integer.parseInt(x, 16),
				Integer.parseInt(y, 16));
		PositionOffset offset1 = new PositionOffset(Integer.parseInt(x1, 16),
				Integer.parseInt(y1, 16));
		PositionOffset offset2 = new PositionOffset(Integer.parseInt(x2, 16),
				Integer.parseInt(y2, 16));

		nodeList.add(offset);
		nodeList.add(offset1);
		nodeList.add(offset2);
		TimEntity entity = new TimEntity(Integer.parseInt(lat, 16),
				Integer.parseInt(lon, 16), Integer.parseInt(altitude, 16),
				Integer.parseInt(viewAngle, 16),
				Integer.parseInt(mutcdCode, 16),
				Integer.parseInt(startYear, 16),
				Integer.parseInt(startTime, 16), Integer.parseInt(durationTime,
						16), Integer.parseInt(priority, 16), Integer.parseInt(
						commonAnchor_lat, 16), Integer.parseInt(
						commonAnchor_lon, 16), Integer.parseInt(
						commonAnchor_elevation, 16), Integer.parseInt(
						commonLaneWidth, 16), Integer.parseInt(
						commonDirectionality, 16), nodeList);
		return entity;

	}

	public static ArrayList<MapEntity> getMap(String data) {// 558
		data = "" + "30820113800107810100830103A58201023081FF8102" + "007B"// id0 44 48
				+ "A20C8004" + "191B0080"// 56 64
				+ "8104" + "CE74E500"// 68 76
				+ "A781EA3039A237800A" + "4E6F727468626F756E64"// 94 114
				+ "8101" + "01"// id1 118 120
				+ "A22630248001" + "01"// 132 34
				+ "8102" + "016E"// 138 142
				+ "8201" + "02"// 146 148
				+ "A3180406" + "E1B1CBF70001"// nodelist 156 168
				+ "0406" + "62139F380002"// 172 184
				+ "0406" + "AF339F380001"// 188 200
				+ "3038A2368009" + "45617374626F756E64"// 212 230
				+ "8101" + "02"// id2 234 236
				+ "A22630248001" + "02"// 248 250
				+ "8102" + "016E"// 254 258
				+ "8201" + "02"// 262 264
				+ "A3180406" + "D10459060001" // 272 284
				+ "0406" + "50DA9F380001"// 288 300
				+ "0406" + "50EC9F380000"// 304 316
				+ "3039A237800A" + "536F757468626F756E64"// 328 348
				+ "8101" + "03"// id3 352 354
				+ "A22630248001" + "03"// 366 368
				+ "8102" + "016E"// 372 376
				+ "8201" + "02"// 380 382
				+ "A3180406" + "C32C2AC00001"// 390 402
				+ "0406" + "5E79122A0001"// 406 418
				+ "0406" + "AF33AF650001"// 422 434
				+ "3038A2368009" + "57657374626F756E64"// 446 464
				+ "8101" + "04" // id4 468 470
				+ "A22630248001" + "04"// 482 484
				+ "8102" + "016E"// 488 492
				+ "8201" + "02"// 496 498
				+ "A3180406" + "E038795E0001" // 506 518
				+ "0406" + "50C4122A0001"// 522 534
				+ "0406" + "9A5460C80001"// 538 550
				+ "87023500";

		String id = data.substring(44, 48);
		String lat = data.substring(56, 64);
		String lon = data.substring(68, 76);
		MapEntity entity = new MapEntity(Long.parseLong(lat, 16),
				Long.parseLong(lon, 16), Integer.parseInt(id, 16));
		// id1
		String name1 = data.substring(94, 114);
		String id1 = data.substring(118, 120);
		String laneNumber1 = data.substring(132, 134);
		String laneWidth1 = data.substring(138, 142);
		String laneAttributes1 = data.substring(146, 148);
		ArrayList<PositionOffset> list1 = new ArrayList<PositionOffset>();
		String x11 = data.substring(156, 160);
		String y11 = data.substring(160, 164);
		String z11 = data.substring(164, 168);
		PositionOffset offset11 = new PositionOffset(Integer.parseInt(x11, 16),
				Integer.parseInt(y11, 16), Integer.parseInt(z11, 16));

		String x12 = data.substring(172, 176);
		String y12 = data.substring(176, 180);
		String z12 = data.substring(180, 184);
		PositionOffset offset12 = new PositionOffset(Integer.parseInt(x12, 16),
				Integer.parseInt(y12, 16), Integer.parseInt(z12, 16));

		String x13 = data.substring(188, 192);
		String y13 = data.substring(192, 196);
		String z13 = data.substring(196, 200);
		PositionOffset offset13 = new PositionOffset(Integer.parseInt(x13, 16),
				Integer.parseInt(y13, 16), Integer.parseInt(z13, 16));
		list1.add(offset11);
		list1.add(offset12);
		list1.add(offset13);

		MapEntity entity1 = new MapEntity(Integer.parseInt(id1, 16),
				Integer.parseInt(laneNumber1, 16), Integer.parseInt(laneWidth1,
						16), Integer.parseInt(laneAttributes1, 16), list1,
				name1);
		// id2
		String name2 = data.substring(212, 230);
		String id2 = data.substring(234, 236);
		String laneNumber2 = data.substring(248, 250);
		String laneWidth2 = data.substring(254, 258);
		String laneAttributes2 = data.substring(262, 264);
		ArrayList<PositionOffset> list2 = new ArrayList<PositionOffset>();
		String x21 = data.substring(272, 276);
		String y21 = data.substring(276, 280);
		String z21 = data.substring(280, 284);
		PositionOffset offset21 = new PositionOffset(Integer.parseInt(x21, 16),
				Integer.parseInt(y21, 16), Integer.parseInt(z21, 16));

		String x22 = data.substring(288, 292);
		String y22 = data.substring(292, 296);
		String z22 = data.substring(296, 300);
		PositionOffset offset22 = new PositionOffset(Integer.parseInt(x22, 16),
				Integer.parseInt(y22, 16), Integer.parseInt(z22, 16));

		String x23 = data.substring(304, 308);
		String y23 = data.substring(308, 312);
		String z23 = data.substring(312, 316);
		PositionOffset offset23 = new PositionOffset(Integer.parseInt(x23, 16),
				Integer.parseInt(y23, 16), Integer.parseInt(z23, 16));
		list2.add(offset21);
		list2.add(offset22);
		list2.add(offset23);

		MapEntity entity2 = new MapEntity(Integer.parseInt(id2, 16),
				Integer.parseInt(laneNumber2, 16), Integer.parseInt(laneWidth2,
						16), Integer.parseInt(laneAttributes2, 16), list2,
				name2);

		// //id3
		String name3 = data.substring(212, 230);
		String id3 = data.substring(352, 354);
		String laneNumber3 = data.substring(366, 368);
		String laneWidth3 = data.substring(372, 376);
		String laneAttributes3 = data.substring(380, 382);
		ArrayList<PositionOffset> list3 = new ArrayList<PositionOffset>();
		String x31 = data.substring(390, 394);
		String y31 = data.substring(394, 398);
		String z31 = data.substring(398, 402);
		PositionOffset offset31 = new PositionOffset(Integer.parseInt(x31, 16),
				Integer.parseInt(y31, 16), Integer.parseInt(z31, 16));
		String x32 = data.substring(406, 410);
		String y32 = data.substring(410, 414);
		String z32 = data.substring(414, 418);
		PositionOffset offset32 = new PositionOffset(Integer.parseInt(x32, 16),
				Integer.parseInt(y32, 16), Integer.parseInt(z32, 16));

		String x33 = data.substring(422, 426);
		String y33 = data.substring(426, 430);
		String z33 = data.substring(430, 434);
		PositionOffset offset33 = new PositionOffset(Integer.parseInt(x33, 16),
				Integer.parseInt(y33, 16), Integer.parseInt(z33, 16));
		list3.add(offset31);
		list3.add(offset32);
		list3.add(offset33);

		int id33 = Integer.parseInt(id3, 16);
		int laneNumber33 = Integer.parseInt(laneNumber3, 16);
		int laneWidth33 = Integer.parseInt(laneWidth3, 16);
		int laneAttributes33 = Integer.parseInt(laneAttributes3, 16);

		MapEntity entity3 = new MapEntity(id33, laneNumber33, laneNumber33,
				laneAttributes33, list3, name3);

		// id4
		String name4 = data.substring(446, 464);
		String id4 = data.substring(468, 470);
		String laneNumber4 = data.substring(482, 484);
		String laneWidth4 = data.substring(488, 492);
		String laneAttributes4 = data.substring(496, 498);
		ArrayList<PositionOffset> list4 = new ArrayList<PositionOffset>();
		String x41 = data.substring(506, 510);
		String y41 = data.substring(510, 514);
		String z41 = data.substring(514, 518);

		PositionOffset offset41 = new PositionOffset(Integer.parseInt(x41, 16),
				Integer.parseInt(y41, 16), Integer.parseInt(z41, 16));
		String x42 = data.substring(522, 526);
		String y42 = data.substring(526, 530);
		String z42 = data.substring(530, 534);
		PositionOffset offset42 = new PositionOffset(Integer.parseInt(x42, 16),
				Integer.parseInt(y42, 16), Integer.parseInt(z42, 16));

		String x43 = data.substring(538, 542);
		String y43 = data.substring(542, 546);
		String z43 = data.substring(546, 550);
		PositionOffset offset43 = new PositionOffset(Integer.parseInt(x43, 16),
				Integer.parseInt(y43, 16), Integer.parseInt(z43, 16));
		list4.add(offset41);
		list4.add(offset42);
		list4.add(offset43);

		MapEntity entity4 = new MapEntity(Integer.parseInt(id4, 16),
				Integer.parseInt(laneNumber4, 16), Integer.parseInt(laneWidth4,
						16), Integer.parseInt(laneAttributes4, 16), list4,
				name4);

		ArrayList<MapEntity> list = new ArrayList<MapEntity>();
		list.add(entity);
		list.add(entity1);
		list.add(entity2);
		list.add(entity3);
		list.add(entity4);
		return list;
	}

}
